#include <iostream>
using namespace std;
#include <map>
#include <string>

class Student{
friend ostream& operator << (ostream& out, const Student& rhs);
	int		id;
	string	name;
public:
	Student(int id, const string& name)
		:id(id),
		name(name)
	{
	
	}

	const string& getName() const { return this->name; }

	bool operator < (const Student& rhs) const
	{
		return this->name < rhs.name;
	}
};

ostream& operator << (ostream& out, const Student& rhs)
{
	out << rhs.id << "\t" << rhs.name;
	return out;
}

bool cmp(const Student& lhs, const Student& rhs)
{
	return lhs.getName() > rhs.getName();
}

int main(int argc, char **argv)
{
	map<Student, double, bool(*)(const Student&, const Student&)> stus(cmp);
	Student tom(1, "tom");
	Student jack(2, "jack");
	Student bob(5, "bob");
	Student willian(4, "willian");

	stus.insert(pair<Student, double>(tom, 60));
	stus.insert(pair<Student, double>(jack, 60));
	stus.insert(pair<Student, double>(bob, 60));

	map<Student, double>::iterator sit = stus.find(tom);
	//查找失败返回尾迭代器，成功返回已经存在的键值对迭代器
	if(sit != stus.end()){
		cout << "查找成功: " << sit->first << "\t" << sit->second << endl;
		//下标修改
		//stus[tom] = 99;
		sit->second = 99;
		//sit->first = willian;
	}


	//显示
	for(map<Student, double>::iterator it = stus.begin(); it != stus.end(); ++it){
		cout << it->first << "\t" << it->second << endl;
	}

	
	return 0;
}
